package com.zyx.enhancement.controller;

import com.alibaba.fastjson2.JSONObject;
import com.zyx.enhancement.common.IpUtils;
import com.zyx.enhancement.service.LocationService;
import com.zyx.enhancement.service.WeatherInfoService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/content-enhancement")
public class ContentEnhancementController {

    @Resource
    private WeatherInfoService weatherInfoService;

    @Resource
    private LocationService locationService;

    /**
     * 查询天气信息
     * @param cityCode 城市编码
     * @return 天气信息
     */
    @GetMapping("/weather/{city}")
    public ResponseEntity<?> queryWeather(@PathVariable("city") String cityCode)
    {
        JSONObject weather = weatherInfoService.queryWeather(cityCode);
        return ResponseEntity.ok().body(weather);
    }

    /**
     * 查询城市信息
     * @param ip 客户端真实IP地址
     * @return 城市编码
     */
    @PostMapping("/location")
    public ResponseEntity<?> queryLocation(@RequestBody String ip)
    {
        String cityCode = locationService.queryCityLocation(ip);
        return ResponseEntity.ok(cityCode);
    }

    // 记录客户端IP地址
    @RequestMapping("/record-ip")
    public ResponseEntity<?> recordClientIp()
    {
        String ip = IpUtils.getClientIp();
        log.info("记录客户端IP地址:{}", ip);
        return ResponseEntity.ok(ip);
    }

    // 推送SMS 消息
    @PostMapping("/send-sms")
    public ResponseEntity<?> sendSms(@RequestBody String content)
    {
        log.info("推送SMS消息:{}", content);
        return ResponseEntity.ok("推送成功");
    }

}
